listmodels: Stop respecting item-type
authorBenjamin Otte <otte@redhat.com>
Sat, 4 Jul 2020 19:47:48 +0000 (21:47 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 5 Jul 2020 00:59:21 +0000 (02:59 +0200)
Simplify all view model APIs and always return G_TYPE_OBJECT as the
item-type for every model.

It turns out nobody uses item-type anyway.

So instead of adding lots of APIs, forcing people to think about it and
trying to figure out how to handle filter or map models that modify item
types, just having an easy life is a better approach.

All the models need to be able to deal with any type of object going
through anyway.

29 files changed:
demos/constraint-editor/constraint-view.c
docs/reference/gtk/gtk4-sections.txt
gtk/gtkcustompaperunixdialog.c
gtk/gtkfilterlistmodel.c
gtk/gtkfilterlistmodel.h
gtk/gtkflattenlistmodel.c
gtk/gtkflattenlistmodel.h
gtk/gtkfontchooserwidget.c
gtk/gtkmaplistmodel.c
gtk/gtkmaplistmodel.h
gtk/gtkmultiselection.c
gtk/gtknoselection.c
gtk/gtkpagesetupunixdialog.c
gtk/gtkprintunixdialog.c
gtk/gtkshortcutcontroller.c
gtk/gtkshortcutmanager.c
gtk/gtksingleselection.c
gtk/gtkslicelistmodel.c
gtk/gtkslicelistmodel.h
gtk/gtksortlistmodel.c
gtk/gtksortlistmodel.h
gtk/gtktreelistmodel.c
gtk/inspector/controllers.c
gtk/inspector/object-tree.c
testsuite/gtk/expression.c
testsuite/gtk/flattenlistmodel.c
testsuite/gtk/maplistmodel.c
testsuite/gtk/slicelistmodel.c
testsuite/gtk/sortlistmodel.c

index 76b4acd8483d03c40db7e589ae5106383105d571..c9d08acab84e70ef7af3b2d91720cedc1fedceb5 100644 (file)
@@ -188,7 +188,7 @@ constraint_view_init (ConstraintView *self)
   g_list_store_append (list, children);
   g_list_store_append (list, guides);
   g_list_store_append (list, constraints);
-  self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list)));
+  self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
   g_object_unref (children);
   g_object_unref (guides);
   g_object_unref (constraints);
index 208151976cebd4d7037754ecd01923f6770f72a4..15bdac5bc3d741cf04ccb9ea93fc24f37cf79b7f 100644 (file)
@@ -1539,7 +1539,6 @@ gtk_custom_filter_get_type
 <TITLE>GtkFilterListModel</TITLE>
 GtkFilterListModel
 gtk_filter_list_model_new
-gtk_filter_list_model_new_for_type
 gtk_filter_list_model_set_model
 gtk_filter_list_model_get_model
 gtk_filter_list_model_set_filter
@@ -2698,7 +2697,6 @@ gtk_size_group_get_type
 <TITLE>GtkSliceListModel</TITLE>
 GtkSliceListModel
 gtk_slice_list_model_new
-gtk_slice_list_model_new_for_type
 gtk_slice_list_model_set_model
 gtk_slice_list_model_get_model
 gtk_slice_list_model_set_offset
@@ -2830,7 +2828,6 @@ gtk_tree_list_row_sorter_get_type
 <TITLE>GtkSortListModel</TITLE>
 GtkSortListModel
 gtk_sort_list_model_new
-gtk_sort_list_model_new_for_type
 gtk_sort_list_model_set_sorter
 gtk_sort_list_model_get_sorter
 gtk_sort_list_model_set_model
index 608a637c88fb5c3e1444840fc216d9a0b2ea83a3..75e471689ca1a07981069255fb5b35402d853dab 100644 (file)
@@ -321,7 +321,7 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
   g_list_store_append (printer_list_list, printer_list);
   g_object_unref (printer_list);
 
-  full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list)));
+  full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
   g_object_unref (printer_list_list);
 
   filter = gtk_custom_filter_new (match_func, NULL, NULL);
index af29154fcbe9b92b270866df6d84f7b43a810450..12a456ca8a6c1694a5f0aaacc5d3a55b53873bf8 100644 (file)
@@ -40,7 +40,6 @@
 enum {
   PROP_0,
   PROP_FILTER,
-  PROP_ITEM_TYPE,
   PROP_MODEL,
   NUM_PROPERTIES
 };
@@ -63,7 +62,6 @@ struct _GtkFilterListModel
 {
   GObject parent_instance;
 
-  GType item_type;
   GListModel *model;
   GtkFilter *filter;
   GtkFilterMatch strictness;
@@ -194,9 +192,7 @@ gtk_filter_list_model_get_nth (GtkRbTree *tree,
 static GType
 gtk_filter_list_model_get_item_type (GListModel *list)
 {
-  GtkFilterListModel *self = GTK_FILTER_LIST_MODEL (list);
-
-  return self->item_type;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -364,10 +360,6 @@ gtk_filter_list_model_set_property (GObject      *object,
       gtk_filter_list_model_set_filter (self, g_value_get_object (value));
       break;
 
-    case PROP_ITEM_TYPE:
-      self->item_type = g_value_get_gtype (value);
-      break;
-
     case PROP_MODEL:
       gtk_filter_list_model_set_model (self, g_value_get_object (value));
       break;
@@ -392,10 +384,6 @@ gtk_filter_list_model_get_property (GObject     *object,
       g_value_set_object (value, self->filter);
       break;
 
-    case PROP_ITEM_TYPE:
-      g_value_set_gtype (value, self->item_type);
-      break;
-
     case PROP_MODEL:
       g_value_set_object (value, self->model);
       break;
@@ -662,18 +650,6 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class)
                            GTK_TYPE_FILTER,
                            GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * GtkFilterListModel:item-type:
-   *
-   * The #GType for elements of this object
-   */
-  properties[PROP_ITEM_TYPE] =
-      g_param_spec_gtype ("item-type",
-                          P_("Item type"),
-                          P_("The type of elements of this object"),
-                          G_TYPE_OBJECT,
-                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkFilterListModel:model:
    *
@@ -697,7 +673,7 @@ gtk_filter_list_model_init (GtkFilterListModel *self)
 
 /**
  * gtk_filter_list_model_new:
- * @model: the model to sort
+ * @model: (allow-none): the model to sort
  * @filter: (allow-none): filter or %NULL to not filter items
  *
  * Creates a new #GtkFilterListModel that will filter @model using the given
@@ -711,10 +687,10 @@ gtk_filter_list_model_new (GListModel *model,
 {
   GtkFilterListModel *result;
 
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (filter == NULL || GTK_IS_FILTER (filter), NULL);
 
   result = g_object_new (GTK_TYPE_FILTER_LIST_MODEL,
-                         "item-type", g_list_model_get_item_type (model),
                          "model", model,
                          "filter", filter,
                          NULL);
@@ -722,26 +698,6 @@ gtk_filter_list_model_new (GListModel *model,
   return result;
 }
 
-/**
- * gtk_filter_list_model_new_for_type:
- * @item_type: the type of the items that will be returned
- *
- * Creates a new empty filter list model set up to return items of type @item_type.
- * It is up to the application to set a proper filter and model to ensure
- * the item type is matched.
- *
- * Returns: a new #GtkFilterListModel
- **/
-GtkFilterListModel *
-gtk_filter_list_model_new_for_type (GType item_type)
-{
-  g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
-
-  return g_object_new (GTK_TYPE_FILTER_LIST_MODEL,
-                       "item-type", item_type,
-                       NULL);
-}
-
 /**
  * gtk_filter_list_model_set_filter:
  * @self: a #GtkFilterListModel
index fcb8dfab5c4756495df0bc9c8dbfb4801ba3df63..c496f302c5e15cf36f8605b06b42c9e4404b5a2e 100644 (file)
@@ -39,8 +39,6 @@ G_DECLARE_FINAL_TYPE (GtkFilterListModel, gtk_filter_list_model, GTK, FILTER_LIS
 GDK_AVAILABLE_IN_ALL
 GtkFilterListModel *    gtk_filter_list_model_new               (GListModel             *model,
                                                                  GtkFilter              *filter);
-GDK_AVAILABLE_IN_ALL
-GtkFilterListModel *    gtk_filter_list_model_new_for_type      (GType                   item_type);
 
 GDK_AVAILABLE_IN_ALL
 void                    gtk_filter_list_model_set_filter        (GtkFilterListModel     *self,
index 78ea061a5399d604b794700edbd049d4d23c705a..fe681b265ebeccb5241411524eed11a5840693fd 100644 (file)
@@ -40,7 +40,6 @@
 
 enum {
   PROP_0,
-  PROP_ITEM_TYPE,
   PROP_MODEL,
   NUM_PROPERTIES
 };
@@ -64,7 +63,6 @@ struct _GtkFlattenListModel
 {
   GObject parent_instance;
 
-  GType item_type;
   GListModel *model;
   GtkRbTree *items; /* NULL if model == NULL */
 };
@@ -157,9 +155,7 @@ gtk_flatten_list_model_get_nth_model (GtkRbTree *tree,
 static GType
 gtk_flatten_list_model_get_item_type (GListModel *list)
 {
-  GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (list);
-
-  return self->item_type;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -299,7 +295,6 @@ gtk_flatten_list_model_add_items (GtkFlattenListModel *self,
     {
       node = gtk_rb_tree_insert_before (self->items, after);
       node->model = g_list_model_get_item (self->model, position + i);
-      g_warn_if_fail (g_type_is_a (g_list_model_get_item_type (node->model), self->item_type));
       g_signal_connect (node->model,
                         "items-changed",
                         G_CALLBACK (gtk_flatten_list_model_items_changed_cb),
@@ -321,10 +316,6 @@ gtk_flatten_list_model_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      self->item_type = g_value_get_gtype (value);
-      break;
-
     case PROP_MODEL:
       gtk_flatten_list_model_set_model (self, g_value_get_object (value));
       break;
@@ -345,10 +336,6 @@ gtk_flatten_list_model_get_property (GObject     *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      g_value_set_gtype (value, self->item_type);
-      break;
-
     case PROP_MODEL:
       g_value_set_object (value, self->model);
       break;
@@ -416,18 +403,6 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class)
   gobject_class->get_property = gtk_flatten_list_model_get_property;
   gobject_class->dispose = gtk_flatten_list_model_dispose;
 
-  /**
-   * GtkFlattenListModel:item-type:
-   *
-   * The #GType for elements of this object
-   */
-  properties[PROP_ITEM_TYPE] =
-      g_param_spec_gtype ("item-type",
-                          P_("Item type"),
-                          P_("The type of elements of this object"),
-                          G_TYPE_OBJECT,
-                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkFlattenListModel:model:
    *
@@ -450,26 +425,20 @@ gtk_flatten_list_model_init (GtkFlattenListModel *self)
 
 /**
  * gtk_flatten_list_model_new:
- * @item_type: The type of items in the to-be-flattened models
- * @model: (nullable) (transfer none): the item to be flattened
+ * @model: (nullable) (transfer none): the model to be flattened
  *
- * Creates a new #GtkFlattenListModel that flattens @list. The
- * models returned by @model must conform to the given @item_type,
- * either by having an identical type or a subtype.
+ * Creates a new #GtkFlattenListModel that flattens @list.
  *
  * Returns: a new #GtkFlattenListModel
  **/
 GtkFlattenListModel *
-gtk_flatten_list_model_new (GType       item_type,
-                            GListModel *model)
+gtk_flatten_list_model_new (GListModel *model)
 {
   GtkFlattenListModel *result;
 
-  g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
   g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   result = g_object_new (GTK_TYPE_FLATTEN_LIST_MODEL,
-                         "item-type", item_type,
                          "model", model,
                          NULL);
 
@@ -481,8 +450,7 @@ gtk_flatten_list_model_new (GType       item_type,
  * @self: a #GtkFlattenListModel
  * @model: (nullable) (transfer none): the new model or %NULL
  *
- * Sets a new model to be flattened. The model must contain items of
- * #GListModel that conform to the item type of @self.
+ * Sets a new model to be flattened.
  **/
 void
 gtk_flatten_list_model_set_model (GtkFlattenListModel *self,
@@ -492,10 +460,6 @@ gtk_flatten_list_model_set_model (GtkFlattenListModel *self,
 
   g_return_if_fail (GTK_IS_FLATTEN_LIST_MODEL (self));
   g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
-  if (model)
-    {
-      g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), G_TYPE_LIST_MODEL));
-    }
 
   if (self->model == model)
     return;
index ec1eaaa84ec7789110fcbb57746c72d00dacda22..c934674ff3a6f37ae6be41167ea23fc32054e166 100644 (file)
@@ -36,8 +36,7 @@ GDK_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (GtkFlattenListModel, gtk_flatten_list_model, GTK, FLATTEN_LIST_MODEL, GObject)
 
 GDK_AVAILABLE_IN_ALL
-GtkFlattenListModel *    gtk_flatten_list_model_new             (GType                   item_type,
-                                                                 GListModel             *model);
+GtkFlattenListModel *    gtk_flatten_list_model_new             (GListModel             *model);
 
 GDK_AVAILABLE_IN_ALL
 void                    gtk_flatten_list_model_set_model        (GtkFlattenListModel    *self,
index 1d4cd53aa8a83c2738074886a7fd9eda0c801d46..42101f29d34f077c66a3a53d033bc5d8a761947f 100644 (file)
@@ -784,7 +784,7 @@ update_fontlist (GtkFontChooserWidget *self)
   if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0)
     model = g_object_ref (G_LIST_MODEL (fontmap));
   else
-    model = G_LIST_MODEL (gtk_flatten_list_model_new (PANGO_TYPE_FONT_FACE, G_LIST_MODEL (fontmap)));
+    model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (fontmap)));
   gtk_filter_list_model_set_model (self->filter_model, model);
   g_object_unref (model);
 }
index b77906fcc97a09b05881074672b06427b5e9cc1b..ea43269c07697fa54f9c27b920c599c107953a3b 100644 (file)
@@ -63,7 +63,6 @@
 enum {
   PROP_0,
   PROP_HAS_MAP,
-  PROP_ITEM_TYPE,
   PROP_MODEL,
   NUM_PROPERTIES
 };
@@ -86,7 +85,6 @@ struct _GtkMapListModel
 {
   GObject parent_instance;
 
-  GType item_type;
   GListModel *model;
   GtkMapListModelMapFunc map_func;
   gpointer user_data;
@@ -145,9 +143,7 @@ gtk_map_list_model_get_nth (GtkRbTree *tree,
 static GType
 gtk_map_list_model_get_item_type (GListModel *list)
 {
-  GtkMapListModel *self = GTK_MAP_LIST_MODEL (list);
-
-  return self->item_type;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -199,11 +195,6 @@ gtk_map_list_model_get_item (GListModel *list,
     }
 
   node->item = self->map_func (g_list_model_get_item (self->model, position), self->user_data);
-  if (!G_TYPE_CHECK_INSTANCE_TYPE (node->item, self->item_type))
-    {
-      g_critical ("Map function returned a %s, but it is not a subtype of the model's type %s",
-                  G_OBJECT_TYPE_NAME (node->item), g_type_name (self->item_type));
-    }
   g_object_add_weak_pointer (node->item, &node->item);
 
   return node->item;
@@ -293,10 +284,6 @@ gtk_map_list_model_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      self->item_type = g_value_get_gtype (value);
-      break;
-
     case PROP_MODEL:
       gtk_map_list_model_set_model (self, g_value_get_object (value));
       break;
@@ -321,10 +308,6 @@ gtk_map_list_model_get_property (GObject     *object,
       g_value_set_boolean (value, self->items != NULL);
       break;
 
-    case PROP_ITEM_TYPE:
-      g_value_set_gtype (value, self->item_type);
-      break;
-
     case PROP_MODEL:
       g_value_set_object (value, self->model);
       break;
@@ -382,18 +365,6 @@ gtk_map_list_model_class_init (GtkMapListModelClass *class)
                             FALSE,
                             GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * GtkMapListModel:item-type:
-   *
-   * The #GType for elements of this object
-   */
-  properties[PROP_ITEM_TYPE] =
-      g_param_spec_gtype ("item-type",
-                          P_("Item type"),
-                          P_("The type of elements of this object"),
-                          G_TYPE_OBJECT,
-                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkMapListModel:model:
    *
@@ -441,7 +412,6 @@ gtk_map_list_model_augment (GtkRbTree *map,
 
 /**
  * gtk_map_list_model_new:
- * @item_type: the #GType to use as the model's item type
  * @model: (allow-none): The model to map or %NULL for none
  * @map_func: (allow-none): map function or %NULL to not map items
  * @user_data: (closure): user data passed to @map_func
@@ -452,19 +422,16 @@ gtk_map_list_model_augment (GtkRbTree *map,
  * Returns: a new #GtkMapListModel
  **/
 GtkMapListModel *
-gtk_map_list_model_new (GType                   item_type,
-                        GListModel             *model,
+gtk_map_list_model_new (GListModel             *model,
                         GtkMapListModelMapFunc  map_func,
                         gpointer                user_data,
                         GDestroyNotify          user_destroy)
 {
   GtkMapListModel *result;
 
-  g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
   g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   result = g_object_new (GTK_TYPE_MAP_LIST_MODEL,
-                         "item-type", item_type,
                          "model", model,
                          NULL);
 
index f0ddcc95249a2a6f9c1b3af45c9fd1fe2f7bbb6e..85a39823abc24c31927d87aaa372cc7c20ee4399 100644 (file)
@@ -53,8 +53,7 @@ G_DECLARE_FINAL_TYPE (GtkMapListModel, gtk_map_list_model, GTK, MAP_LIST_MODEL,
 typedef gpointer (* GtkMapListModelMapFunc) (gpointer item, gpointer user_data);
 
 GDK_AVAILABLE_IN_ALL
-GtkMapListModel *       gtk_map_list_model_new                  (GType                   item_type,
-                                                                 GListModel             *model,
+GtkMapListModel *       gtk_map_list_model_new                  (GListModel             *model,
                                                                  GtkMapListModelMapFunc  map_func,
                                                                  gpointer                user_data,
                                                                  GDestroyNotify          user_destroy);
index e8bd0759efcea1aac564d913d637eb60fe78068d..ad6d3857deff44a85267897d6ef3c4e632c5baf0 100644 (file)
@@ -62,9 +62,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
 static GType
 gtk_multi_selection_get_item_type (GListModel *list)
 {
-  GtkMultiSelection *self = GTK_MULTI_SELECTION (list);
-
-  return g_list_model_get_item_type (self->model);
+  return G_TYPE_OBJECT;
 }
 
 static guint
index 72ace9a5a51a042de8ec292f828430fc9f7ed8b7..652b1487357f864b4098b5584a473e4e3f3d90c7 100644 (file)
@@ -60,9 +60,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
 static GType
 gtk_no_selection_get_item_type (GListModel *list)
 {
-  GtkNoSelection *self = GTK_NO_SELECTION (list);
-
-  return g_list_model_get_item_type (self->model);
+  return G_TYPE_OBJECT;
 }
 
 static guint
index 5e2679affddc8f874fc14cd14a4db14ae3d3a71e..2e353c0033b9b2b39fcd87409b8fb1439249db99 100644 (file)
@@ -306,7 +306,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
   g_list_store_append (store, dialog->page_setup_list);
   g_list_store_append (store, dialog->custom_paper_list);
   g_list_store_append (store, dialog->manage_papers_list);
-  paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store)));
+  paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
   gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
   g_object_unref (store);
   g_object_unref (paper_size_list);
@@ -321,7 +321,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
   g_list_store_append (printer_list_list, printer_list);
   g_object_unref (printer_list);
 
-  full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list)));
+  full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
 
   filter = gtk_custom_filter_new (match_func, NULL, NULL);
   dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
index 37a9e58e6f119d54137d04209b5b5c9a7452ec37..dab4548b495e70ba359ada9b04eec2eb9dd58570 100644 (file)
@@ -806,7 +806,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   g_list_store_append (store, dialog->page_setup_list);
   g_list_store_append (store, dialog->custom_paper_list);
   g_list_store_append (store, dialog->manage_papers_list);
-  paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store)));
+  paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
   gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
   g_object_unref (store);
   g_object_unref (paper_size_list);
@@ -1056,7 +1056,7 @@ load_print_backends (GtkPrintUnixDialog *dialog)
       g_list_store_append (lists, gtk_print_backend_get_printers (backend));
     }
 
-  model = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (lists)));
+  model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
 
   g_object_unref (lists);
 
index 19c3d793dd7619f7d9a234386a6a622e8ca8130b..1b995f5098fb23447482ee886d898ff5c575ab3f 100644 (file)
@@ -110,7 +110,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
 static GType
 gtk_shortcut_controller_list_model_get_item_type (GListModel *list)
 {
-  return GTK_TYPE_SHORTCUT;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -198,12 +198,6 @@ gtk_shortcut_controller_set_property (GObject      *object,
     case PROP_MODEL:
       {
         GListModel *model = g_value_get_object (value);
-        if (model && g_list_model_get_item_type (model) != GTK_TYPE_SHORTCUT)
-          {
-            g_warning ("Setting a model with type '%s' on a shortcut controller that requires 'GtkShortcut'",
-                       g_type_name (g_list_model_get_item_type (model)));
-            model = NULL;
-          }
         if (model == NULL)
           {
             self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
@@ -309,6 +303,11 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
 
       index = (self->last_activated + 1 + i) % g_list_model_get_n_items (self->shortcuts);
       shortcut = g_list_model_get_item (self->shortcuts, index);
+      if (!GTK_IS_SHORTCUT (shortcut))
+        {
+          g_object_unref (shortcut);
+          continue;
+        }
 
       switch (gtk_shortcut_trigger_trigger (gtk_shortcut_get_trigger (shortcut), event, enable_mnemonics))
         {
@@ -484,7 +483,8 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
   for (i = 0, p = g_list_model_get_n_items (G_LIST_MODEL (controller)); i < p; i++)
     {
       GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
-      update_accel (shortcut, widget, TRUE);
+      if (GTK_IS_SHORTCUT (shortcut))
+        update_accel (shortcut, widget, TRUE);
       g_object_unref (shortcut);
     }
 
@@ -506,7 +506,8 @@ gtk_shortcut_controller_unset_widget (GtkEventController *controller)
   for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
     {
       GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
-      update_accel (shortcut, widget, FALSE);
+      if (GTK_IS_SHORTCUT (shortcut))
+        update_accel (shortcut, widget, FALSE);
       g_object_unref (shortcut);
     }
 #endif
@@ -697,7 +698,6 @@ GtkEventController *
 gtk_shortcut_controller_new_for_model (GListModel *model)
 {
   g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
-  g_return_val_if_fail (g_list_model_get_item_type (model) == GTK_TYPE_SHORTCUT, NULL);
 
   return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
                        "model", model,
index 9aa3577703f081ded847e50b2db7432564f41aa6..a6f2559b1df003f25c0364a8dc631733e0805a63 100644 (file)
@@ -49,7 +49,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
   GtkEventController *controller;
 
   store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
-  model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
+  model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
   g_object_unref (store);
   g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
   controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
@@ -57,7 +57,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
   gtk_widget_add_controller (widget, controller);
 
   store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
-  model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
+  model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
   g_object_unref (store);
   g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
   controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
index bd35aed7820fff11e77cb3bf6b824dd7a143d00b..70f0beab275c9ba9b06ae7beb62255db804013d8 100644 (file)
@@ -72,9 +72,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
 static GType
 gtk_single_selection_get_item_type (GListModel *list)
 {
-  GtkSingleSelection *self = GTK_SINGLE_SELECTION (list);
-
-  return g_list_model_get_item_type (self->model);
+  return G_TYPE_OBJECT;
 }
 
 static guint
index d002252fffb04c93a20a0d0f52c4d67771670980..8d0273c0371ed4b3fe605156d830a95e7d861d26 100644 (file)
@@ -41,7 +41,6 @@
 
 enum {
   PROP_0,
-  PROP_ITEM_TYPE,
   PROP_MODEL,
   PROP_OFFSET,
   PROP_SIZE,
@@ -52,7 +51,6 @@ struct _GtkSliceListModel
 {
   GObject parent_instance;
 
-  GType item_type;
   GListModel *model;
   guint offset;
   guint size;
@@ -70,9 +68,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 static GType
 gtk_slice_list_model_get_item_type (GListModel *list)
 {
-  GtkSliceListModel *self = GTK_SLICE_LIST_MODEL (list);
-
-  return self->item_type;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -182,10 +178,6 @@ gtk_slice_list_model_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      self->item_type = g_value_get_gtype (value);
-      break;
-
     case PROP_MODEL:
       gtk_slice_list_model_set_model (self, g_value_get_object (value));
       break;
@@ -214,10 +206,6 @@ gtk_slice_list_model_get_property (GObject     *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      g_value_set_gtype (value, self->item_type);
-      break;
-
     case PROP_MODEL:
       g_value_set_object (value, self->model);
       break;
@@ -265,18 +253,6 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
   gobject_class->get_property = gtk_slice_list_model_get_property;
   gobject_class->dispose = gtk_slice_list_model_dispose;
 
-  /**
-   * GtkSliceListModel:item-type:
-   *
-   * The #GType for elements of this object
-   */
-  properties[PROP_ITEM_TYPE] =
-      g_param_spec_gtype ("item-type",
-                          P_("Item type"),
-                          P_("The type of elements of this object"),
-                          G_TYPE_OBJECT,
-                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkSliceListModel:model:
    *
@@ -324,7 +300,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self)
 
 /**
  * gtk_slice_list_model_new:
- * @model: (transfer none): The model to use
+ * @model: (transfer none) (allow-none): The model to use
  * @offset: the offset of the slice
  * @size: maximum size of the slice
  *
@@ -338,35 +314,15 @@ gtk_slice_list_model_new (GListModel *model,
                           guint       offset,
                           guint       size)
 {
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
   return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
-                       "item-type", g_list_model_get_item_type (model),
                        "model", model,
                        "offset", offset,
                        "size", size,
                        NULL);
 }
 
-/**
- * gtk_slice_list_model_new_for_type:
- * @item_type: the type of items
- *
- * Creates a new empty #GtkSliceListModel for the given @item_type that
- * can be set up later.
- *
- * Returns: a new empty #GtkSliceListModel
- **/
-GtkSliceListModel *
-gtk_slice_list_model_new_for_type (GType item_type)
-{
-  g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
-
-  return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
-                       "item-type", item_type,
-                       NULL);
-}
-
 /**
  * gtk_slice_list_model_set_model:
  * @self: a #GtkSliceListModel
index 837e67ef7a22f9922b7b55090ee1f64a8a9d23a7..d1b0cd8edc4c54e461e4cf0514e82ebf8d7ff82b 100644 (file)
@@ -40,8 +40,6 @@ GDK_AVAILABLE_IN_ALL
 GtkSliceListModel *     gtk_slice_list_model_new                (GListModel             *model,
                                                                  guint                   offset,
                                                                  guint                   size);
-GDK_AVAILABLE_IN_ALL
-GtkSliceListModel *     gtk_slice_list_model_new_for_type       (GType                   item_type);
 
 GDK_AVAILABLE_IN_ALL
 void                    gtk_slice_list_model_set_model          (GtkSliceListModel      *self,
index 0406d1e86f8a8ff43b79cb6b8d1eff27a2ec0621..06e1c6f3b20aaa1cf7eed5400387116fe4a1fc92 100644 (file)
@@ -42,7 +42,6 @@
 
 enum {
   PROP_0,
-  PROP_ITEM_TYPE,
   PROP_MODEL,
   PROP_SORTER,
   NUM_PROPERTIES
@@ -54,7 +53,6 @@ struct _GtkSortListModel
 {
   GObject parent_instance;
 
-  GType item_type;
   GListModel *model;
   GtkSorter *sorter;
 
@@ -89,9 +87,7 @@ gtk_sort_list_entry_free (gpointer data)
 static GType
 gtk_sort_list_model_get_item_type (GListModel *list)
 {
-  GtkSortListModel *self = GTK_SORT_LIST_MODEL (list);
-
-  return self->item_type;
+  return G_TYPE_OBJECT;
 }
 
 static guint
@@ -262,10 +258,6 @@ gtk_sort_list_model_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      self->item_type = g_value_get_gtype (value);
-      break;
-
     case PROP_MODEL:
       gtk_sort_list_model_set_model (self, g_value_get_object (value));
       break;
@@ -290,10 +282,6 @@ gtk_sort_list_model_get_property (GObject     *object,
 
   switch (prop_id)
     {
-    case PROP_ITEM_TYPE:
-      g_value_set_gtype (value, self->item_type);
-      break;
-
     case PROP_MODEL:
       g_value_set_object (value, self->model);
       break;
@@ -405,18 +393,6 @@ gtk_sort_list_model_class_init (GtkSortListModelClass *class)
                             GTK_TYPE_SORTER,
                             GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * GtkSortListModel:item-type:
-   *
-   * The #GType for items of this model
-   */
-  properties[PROP_ITEM_TYPE] =
-      g_param_spec_gtype ("item-type",
-                          P_("Item type"),
-                          P_("The type of items of this list"),
-                          G_TYPE_OBJECT,
-                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkSortListModel:model:
    *
@@ -439,7 +415,7 @@ gtk_sort_list_model_init (GtkSortListModel *self)
 
 /**
  * gtk_sort_list_model_new:
- * @model: the model to sort
+ * @model: (allow-none): the model to sort
  * @sorter: (allow-none): the #GtkSorter to sort @model with
  *
  * Creates a new sort list model that uses the @sorter to sort @model.
@@ -452,11 +428,10 @@ gtk_sort_list_model_new (GListModel *model,
 {
   GtkSortListModel *result;
 
-  g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+  g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
   g_return_val_if_fail (sorter == NULL || GTK_IS_SORTER (sorter), NULL);
 
   result = g_object_new (GTK_TYPE_SORT_LIST_MODEL,
-                         "item-type", g_list_model_get_item_type (model),
                          "model", model,
                          "sorter", sorter,
                          NULL);
@@ -464,26 +439,6 @@ gtk_sort_list_model_new (GListModel *model,
   return result;
 }
 
-/**
- * gtk_sort_list_model_new_for_type:
- * @item_type: the type of the items that will be returned
- *
- * Creates a new empty sort list model set up to return items of type @item_type.
- * It is up to the application to set a proper sort function and model to ensure
- * the item type is matched.
- *
- * Returns: a new #GtkSortListModel
- **/
-GtkSortListModel *
-gtk_sort_list_model_new_for_type (GType item_type)
-{
-  g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
-
-  return g_object_new (GTK_TYPE_SORT_LIST_MODEL,
-                       "item-type", item_type,
-                       NULL);
-}
-
 /**
  * gtk_sort_list_model_set_model:
  * @self: a #GtkSortListModel
@@ -500,10 +455,6 @@ gtk_sort_list_model_set_model (GtkSortListModel *self,
 
   g_return_if_fail (GTK_IS_SORT_LIST_MODEL (self));
   g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
-  if (model)
-    {
-      g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), self->item_type));
-    }
 
   if (self->model == model)
     return;
index 3e009502e2c3020d999d232dec4a297a215d2c54..b78029af2f6d0e74d77eaeea5e20ed6ab55c7cd7 100644 (file)
@@ -40,9 +40,6 @@ G_DECLARE_FINAL_TYPE (GtkSortListModel, gtk_sort_list_model, GTK, SORT_LIST_MODE
 GDK_AVAILABLE_IN_ALL
 GtkSortListModel *      gtk_sort_list_model_new                 (GListModel            *model,
                                                                  GtkSorter             *sorter);
-GDK_AVAILABLE_IN_ALL
-GtkSortListModel *      gtk_sort_list_model_new_for_type        (GType                  item_type);
-
 GDK_AVAILABLE_IN_ALL
 void                    gtk_sort_list_model_set_sorter          (GtkSortListModel       *self,
                                                                  GtkSorter              *sorter);
index 246d9f2eb765e6e44d820442aa61ca0c8d9e5dbd..4311acb9d3422eede7b821c44c8a1c21bed8aa84 100644 (file)
@@ -533,16 +533,6 @@ gtk_tree_list_model_expand_node (GtkTreeListModel *self,
   if (model == NULL)
     return 0;
   
-  if (!g_type_is_a (g_list_model_get_item_type (model), g_list_model_get_item_type (self->root_node.model)))
-    {
-      g_critical ("The GtkTreeListModelCreateModelFunc for %p returned a model with item type \"%s\" "
-                  "but \"%s\" is required.",
-                  self,
-                  g_type_name (g_list_model_get_item_type (model)),
-                  g_type_name (g_list_model_get_item_type (self->root_node.model)));
-      return 0;
-    }
-
   gtk_tree_list_model_init_node (self, node, model);
 
   tree_node_mark_dirty (node);
@@ -576,7 +566,7 @@ gtk_tree_list_model_get_item_type (GListModel *list)
   GtkTreeListModel *self = GTK_TREE_LIST_MODEL (list);
 
   if (self->passthrough)
-    return g_list_model_get_item_type (self->root_node.model);
+    return G_TYPE_OBJECT;
   else
     return GTK_TYPE_TREE_LIST_ROW;
 }
index d20bef493b918490b4514b8ccc6cf699be97517b..0eae1caafdabef87dc98d47138d6598f6439f43c 100644 (file)
@@ -245,10 +245,10 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
   self->model = gtk_property_lookup_list_model_new (GTK_TYPE_WIDGET, "parent");
   gtk_property_lookup_list_model_set_object (self->model, object);
 
-  map_model = gtk_map_list_model_new (G_TYPE_LIST_MODEL, G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
+  map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
   g_object_unref (self->model);
 
-  flatten_model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, G_LIST_MODEL (map_model));
+  flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model));
 
   sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL);
   sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter);
index add6da624c960d4b8e18126c9b5a74c0cfe428df..44d8cf0fc3aa0b3e28f9cf3a26f2ab9e834ec0a5 100644 (file)
@@ -130,7 +130,7 @@ object_tree_widget_get_children (GObject *object)
   g_list_store_append (list, sublist);
   g_object_unref (sublist);
 
-  flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
+  flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
   g_object_unref (list);
 
   return G_LIST_MODEL (flatten);
@@ -225,7 +225,7 @@ list_model_for_properties (GObject     *object,
       g_object_unref (tmp);
     }
 
-  result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (concat)));
+  result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
   g_object_unref (concat);
   return result;
 }
@@ -330,7 +330,7 @@ object_tree_tree_view_get_children (GObject *object)
   g_object_unref (selection);
   g_list_store_append (result_list, columns);
   g_object_unref (columns);
-  result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
+  result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
   g_object_unref (result_list);
 
   return G_LIST_MODEL (result);
@@ -353,7 +353,7 @@ object_tree_column_view_get_children (GObject *object)
   g_list_store_append (result_list, sublist);
   g_object_unref (sublist);
 
-  result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
+  result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
   g_object_unref (result_list);
 
   return G_LIST_MODEL (result);
@@ -640,7 +640,7 @@ object_get_children (GObject *object)
 
   if (result_list)
     {
-      result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list)));
+      result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
       g_object_unref (result_list);
     }
 
@@ -1179,7 +1179,7 @@ create_root_model (GdkDisplay *display)
   g_list_store_append (list, special);
   g_object_unref (special);
 
-  filter = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT);
+  filter = gtk_filter_list_model_new (NULL, NULL);
   custom_filter = gtk_custom_filter_new (toplevel_filter_func,
                                          display, NULL);
   gtk_filter_list_model_set_filter (filter, custom_filter);
@@ -1187,7 +1187,7 @@ create_root_model (GdkDisplay *display)
   g_list_store_append (list, filter);
   g_object_unref (filter);
 
-  flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
+  flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
   g_object_unref (list);
   return G_LIST_MODEL (flatten);
 }
index d8c75e527bcfaf47014b9fef9060680f17202546..08b6e4d97dcb86334725e9ac4b5507219eda3c65 100644 (file)
@@ -492,7 +492,7 @@ test_bind_child (void)
                                       "filter");
 
   filter = gtk_string_filter_new ();
-  child = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT);
+  child = gtk_filter_list_model_new (NULL, NULL);
   gtk_filter_list_model_set_filter (child, filter);
   target = gtk_filter_list_model_new (G_LIST_MODEL (child), NULL);
   g_object_unref (child);
index dd56e37464c64b18991cc0ff8f877aca714ab9cb..12fc279d18b13a0192cfc9f1cde00da5c12d7bdd 100644 (file)
@@ -210,7 +210,7 @@ new_model (GListStore *store)
   GtkFlattenListModel *result;
   GString *changes;
 
-  result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (store));
+  result = gtk_flatten_list_model_new (G_LIST_MODEL (store));
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
   g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
index 5b6af7b5e450204f71c1bec50338f80308bd228d..94a437f842ff0d4675a2ebf772cd69b5e6a37cff 100644 (file)
@@ -196,7 +196,7 @@ new_model (GListStore *store)
   GtkMapListModel *result;
   GString *changes;
 
-  result = gtk_map_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
+  result = gtk_map_list_model_new (G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
   g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
index c3ae685c5935135453aeef2c79cd898f2658f44f..631444182fd8c06fcbb874dd498991c74d046a0f 100644 (file)
@@ -191,11 +191,7 @@ new_model (GListStore *store, guint offset, guint size)
   GtkSliceListModel *result;
   GString *changes;
 
-  result = gtk_slice_list_model_new_for_type (G_TYPE_OBJECT);
-  if (store)
-    gtk_slice_list_model_set_model (result, G_LIST_MODEL (store));
-  gtk_slice_list_model_set_offset (result, offset);
-  gtk_slice_list_model_set_size (result, size);
+  result = gtk_slice_list_model_new (G_LIST_MODEL (store), offset, size);
 
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
index e0ed7e37df2356e8ea9603c48e88c56c516b83c5..e7a3004d9ddee780ed4fa7805618eafdf3377046 100644 (file)
@@ -203,7 +203,7 @@ new_model (gpointer model)
       g_object_unref (sorter);
     }
   else
-    result = gtk_sort_list_model_new_for_type (G_TYPE_OBJECT);
+    result = gtk_sort_list_model_new (NULL, NULL);
 
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);